package com.ewhale.feitengguest.ui.user.message;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.ewhale.feitengguest.R;
import com.ewhale.feitengguest.ui.user.message.chat.Constant;
import com.ewhale.feitengguest.ui.user.message.chat.IMChatFragment;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.helpdesk.easeui.recorder.MediaManager;
import com.orhanobut.hawk.Hawk;
import com.simga.library.activity.MBaseActivity;
import com.simga.library.base.IPresenter;
import com.simga.library.base.IView;
import com.simga.library.utils.CheckUtil;
import com.simga.library.utils.HawkKey;


/**
 * Created by magic on 2017/5/8.
 */

public class IMChatActivity extends MBaseActivity<IPresenter> implements IView {
    private IMChatFragment chatFragment;
    private String toChatUsername;
    private String nickName;
    private String avatar;

    public static void open(Context activity, String toChatUsername, String nickName, String userAvatar) {
        activity.startActivity(new Intent(activity, IMChatActivity.class)
                .putExtra(EaseConstant.EXTRA_USER_ID, CheckUtil.isNull(toChatUsername) ? Constant.DEFAULT_CUSTOMER_ACCOUNT : toChatUsername)
                .putExtra(EaseConstant.EXTRA_USER_NICK_NAME, nickName)
                .putExtra(EaseConstant.EXTRA_USER_AVATAR, userAvatar));
    }


    @Override
    protected int getViewId() {
        return R.layout.activity_biz_chat;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setTitle(nickName);
        Hawk.put(HawkKey.FRIEND_AVATAR, avatar);
        Hawk.put(HawkKey.FRIEND_NICK_NAME, nickName);
        chatFragment = new IMChatFragment();
        chatFragment.setArguments(getIntent().getExtras());
        getSupportFragmentManager().beginTransaction().add(R.id.container, chatFragment).commit();
    }

    @Override
    protected boolean isUseBaseTitleBar() {
        return true;
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onGetBundle(Bundle bundle) {
        nickName = getIntent().getExtras().getString(EaseConstant.EXTRA_USER_NICK_NAME);
        toChatUsername = getIntent().getExtras().getString(EaseConstant.EXTRA_USER_ID);
        avatar = getIntent().getExtras().getString(EaseConstant.EXTRA_USER_AVATAR);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MediaManager.release();
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    public void showProLoading() {

    }

    @Override
    public void dimissProLoading() {

    }

    @Override
    public void showErrorMessage(int postCode, String code, String message) {

    }

}
